package day20170505.homework.ch01;

import org.junit.Before;
import org.junit.Test;

/**
 * 链表junit测试(data里面装对象)
 * @author 罗智壕-13424431416
 *
 * 2017年5月5日
 */
public class IStudentLinkTest {
	
	/**
	 * 初始化链表
	 */
	private IStudentLinkImpl link;
	
	/**
	 * 在所有方法执行前执行（包括增加）
	 * @throws Exception
	 */
	@Before
	public void before() throws Exception {
		Node head = new Node();
		link = new IStudentLinkImpl(head);
		
		Node node1 = new Node();
		Student stu1 = new Student();
		stu1.setName("奥巴马");
		stu1.setAge(30);
		stu1.setSex('男');
		node1.setData(stu1);
		link.addStudent(node1);
		
		Node node2 = new Node();
		Student stu2 = new Student();
		stu2.setName("习近平");
		stu2.setAge(20);
		stu2.setSex('男');
		node2.setData(stu2);
		link.addStudent(node2);
		
		Node node3 = new Node();
		Student stu3 = new Student();
		stu3.setName("小红");
		stu3.setAge(18);
		stu3.setSex('女');
		node3.setData(stu3);
		link.addStudent(node3);
	}
	
	/**
	 * 打印测试
	 * @throws Exception
	 */
	@Test
	public void printStudentTest() throws Exception {
		link.printStudent();
	}
	
	/**
	 * 打印女生测试
	 * @throws Exception
	 */
	@Test
	public void printGirlsTest() throws Exception {
		link.printGirls();
	}
	
	/**
	 * 把制定的姓名的学生的年龄修改为age测试
	 * @throws Exception
	 */
	@Test
	public void updateStudentTest() throws Exception {
		link.updateStudent("小红", 50);
		printStudentTest();
	}
	
	/**
	 * 删除指定的学生
	 * @throws Exception
	 */
	@Test
	public void deleteStudentTest() throws Exception {
		Student student = new Student();
		student.setName("小红");
		link.deleteStudent(student);
		printStudentTest();
		
	}
	
	/**
	 * 在参照物学生parentStudent的后面添加1个学生insertsSudent测试
	 * @throws Exception
	 */
	@Test
	public void insertStudentTest() throws Exception {
		Node node = new Node();
		Student stu = new Student();
		stu.setName("小红");
		node.setData(stu);
		
		Node node2 = new Node();
		Student stu2 = new Student();
		stu2.setName("徐晓东");
		stu2.setAge(40);
		stu2.setSex('男');
		node2.setData(stu2);
		
		link.insertStudent(node, node2);
		link.printStudent();
	}
}
